package com.example.heraclitoapp;

//import java.util.List;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SelectedAdapterAgent extends ArrayAdapter {

	// used to keep selected position in ListView
	private int selectedPos = -1; // init value for not-selected

	public SelectedAdapterAgent(Context context, int textViewResourceId,
			String[] objects) {
		super(context, textViewResourceId, objects);
	}

	public void setSelectedPosition(int pos) {
		selectedPos = pos;
		// inform the view of this change
		notifyDataSetChanged();
	}

	public int getSelectedPosition() {
		return selectedPos;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;

		// only inflate the view if it's null
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) this.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.selected_row, null);
		}

		// get text view
		TextView label = (TextView) v.findViewById(R.id.txtExample);

		// change the row color based on selected state
		if (selectedPos == position) {
			label.setBackgroundColor(Color.parseColor("#6633b5e5"));
			//label.setBackgroundColor(FF33B5E5);
		} else {
			label.setBackgroundColor(Color.TRANSPARENT);
		}

		label.setText(this.getItem(position).toString());
		/*
		 * // to use something other than .toString() MyClass myobj =
		 * (MyClass)this.getItem(position);
		 * label.setText(myobj.myReturnsString());
		 */
		return (v);
	}

}